var express = require('express');
var app = express();
// 引入http模块
var http = require('http');
// 用http模块创建一个服务并把express的实例挂载上去
var server = http.Server(app);
// 引入socket.io并立即实例化，把server挂载上去
var io = require('socket.io')(server);
var onlieCount = 0;
const sperck = []
    // 新用户连接进来时
io.on('connection', function(socket) {
    onlieCount++;
    var a = 0;
    socket.emit('', onlieCount);

    // (() => setInterval(() => {
    //     io.emit('notice', a++);
    // }, 6000))();
    console.log('有一个人进来了,' + '现在有' + onlieCount + '人在线！');
    // 当有用户断开时
    socket.on('change', function(msg) {
        console.log(msg);



    })
    socket.on('emitChat', function(data) {
        sperck.push(data);
        // sperck = []


        // console.log(data);

        socket.broadcast.emit('notice', sperck);
    })
    socket.on('disconnect', function() {
        onlieCount--;

        console.log(socket.id + '离开了,' + '现在有' + onlieCount + '人在线！');
    });;
    socket.compress('users', function(data) {
        console.log(data);

    })
});